<template>
	<view class="container">
		<!--头部-->
		<view class="status_bar"></view>
		<view class="head flex-row">
			<view class="left" @click="goBack"><uni-icons type="arrowleft" size="24" color="#333"></uni-icons></view>
			<view class="center">现场培训</view>
			<view class="right" @click="toSign">
				<uni-icons type="scan" size="20" color="#1692DC"></uni-icons>
			</view>
		</view>
		<scroll-view scroll-y="true" class="body">
			<!--列表-->
			<view v-if="list.length" class="scroll">
				<view v-for="(item, index) in list" :key="index" @click="toDetail(item)" class="card">
					<view class="title flex-row">
						<view class="name">培训主题：{{ item.title }}</view>
					</view>
					<view class="item"><view>培训讲师：{{ item.techer }}</view></view>
					<view class="item"><view>培训附件：<text>查看附件</text></view></view>
					<view class="item"><view>培训内容：{{ item.content }}</view></view>
					<view class="item flex-row btns">
						<view class="btn" v-if="item.status == 1">正在学习</view>
						<view class="btn" v-if="item.status == 2">已学习</view>
						<view class="btn error" v-if="!item.status">未参与</view>
					</view>
				</view>
				<view class="nodata">没有更多了~</view>
			</view>
			<view v-else class="nodata">没有更多了~</view>
		</scroll-view>
	</view>
</template>

<script>
import uniIcons from "@/components/uni-icons/uni-icons.vue";
export default{
	components: { uniIcons },
	data(){
		return {
			userid: uni.getStorageSync('userid'),
			page: 1,
			total: 1,
			list: []
		}
	},
	onLoad(){
		this.getList();
	},
	methods: {
		goBack(){
			uni.navigateBack();
		},
		toDetail(item){
			uni.navigateTo({url: 'detail?id='+item.id});
		},
		// 扫码
		toSign(){
			uni.scanCode({
				onlyFromCamera: true,
				success: (res)=>{
					let result = res.result;
					result = result.split('{')[1];
					result = result.split('}')[0];
					result = result.split(', ');
					let study_id = result[0].split('=')[1];
					let type = result[1].split('=')[1];
					uni.navigateTo({
						url: 'detail?id='+study_id+'&type='+type
					})
				}
			})
		},
		// 获取列表
		getList(){
			let _this = this;
			uni.request({
				url: this.$API.eduSafeTrainScene,
				data: { userid: this.userid },
				header: this.$API.get_head(),
				success: (res)=>{
					_this.total = res.data.total;
					
					// 判断是第一页还是后续页
					let data = res.data.rows;
					if(_this.page == 1){
						_this.list = data;
					}else{
						_this.list = _this.list.concat(data);
					}
				}
			})
		},
		// 分页加载
		getNextPageData(){
			this.page++;
			if(this.page < this.total){
				this.getList();
			}
		}
	}
}
</script>

<style scoped>
.status_bar{
	width: 100%;
	height: var(--status-bar-height);
	background: #fff;
}

.body{
	height: calc(100vh - 88upx - var(--status-bar-height));
}

/*卡片*/
.card{
	background: #fff;
	margin: 20upx 20upx 0;
	border-radius: 16upx;
	padding: 14upx 20upx 8upx;
	border: 2upx solid #F6F6F6;
	box-shadow: 0 0 4upx #eee;
}
.card .title{
	margin-bottom: 6upx;
}
.card .title view{
	height: 42upx;
	font-size: 28upx;
}
.card .title view.name{
	text-indent: 20upx;
	position: relative;
}
.card .title view.name::before{
	content: '';
	width: 10upx;
	height: 26upx;
	background: #5F96F2;
	border-radius: 4upx;
	position: absolute;
	top: 14upx;
	left: 0;
}
.card .item{
	text-indent: 20upx;
}
.card .item text{
	color: #41A4E8;
}
.card .item.btns{
	margin-bottom: 16upx;
	padding-left: 20upx;
	padding-top: 10upx;
	justify-content: flex-start;
}
.card .item.btns .btn{
	color: #fff;
	width: 160upx;
	height: 52upx;
	font-size: 26upx;
	line-height: 52upx;
	border-radius: 6upx;
	text-align: center;
	text-indent: 0;
	margin-right: 20upx;
	background-color: #1692DC;
}
.card .item.btns .btn.error{
	background: red;
}
</style>
